package com.appspot.diasporajava.controller;

import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.appspot.diasporajava.dao.PodDao;
import com.appspot.diasporajava.dao.UserDao;
import com.appspot.diasporajava.entities.Pod;
import com.appspot.diasporajava.federation.PublicFeed;
import com.appspot.diasporajava.manager.FederationManager;
import com.appspot.diasporajava.manager.FeedManager;

@Controller
public class DatabaseController {
	private Log log = LogFactory.getLog(DatabaseController.class);

	@Autowired
	PublicFeed publicFeed;

	@Autowired
	PodDao<Pod,Long> podDao;

	@Autowired
	FederationManager federationManager;
	
	@Autowired
	UserDao userDao;
	
	@Autowired
	FeedManager feedManager;
	
	@RequestMapping({ "/persistence" })
	public String persistence() {

		Pod pod = new Pod();
		pod.setName("diasp.org");
		pod.setDomainName("diasp.org");
		pod.setTemplate("https://diasp.org/webfinger?q={uri}");

		pod = podDao.create(pod);
		log.debug(pod);

		log.debug(podDao.countAll(new HashMap()));
		// ModelAndView modelAndView = new ModelAndView();
		// return modelAndView;
		return "MyView";
	}
	
	@RequestMapping({"/updateFeeds"})
	public String updateFeeds(){
		feedManager.updateFeeds();
		return "MyView";
	}
}
